package cn.stronglink.assetmanage.business.inspection.presenter;

import android.graphics.Bitmap;

import java.io.IOException;

import cn.stronglink.assetmanage.MyApplication;
import cn.stronglink.assetmanage.R;
import cn.stronglink.assetmanage.business.inspection.model.RepairDetailModel;
import cn.stronglink.assetmanage.business.inspection.view.repairDetail.RepairDetailView;
import cn.stronglink.assetmanage.business.inspection.view.resiger.RepairRegisterView;
import cn.stronglink.assetmanage.entity.Asset;
import cn.stronglink.assetmanage.entity.RepailDetail;
import cn.stronglink.assetmanage.entity.SearchAsset;
import cn.stronglink.assetmanage.index.base.BasePresenter;
import okhttp3.Call;
import okhttp3.Response;

/**
 * Created by zhengjinglan on 2018/6/20.
 */

public class RepairDetailPresenter implements RepairDetailModel.onRepairDetailListener {
    private RepairDetailModel repairDetailModel;
    private RepairDetailView regisgerDetailView;

    public RepairDetailPresenter(RepairDetailModel repairDetailModel, RepairDetailView regisgerDetailView) {
        this.repairDetailModel = repairDetailModel;
        this.regisgerDetailView = regisgerDetailView;
        this.repairDetailModel.setCheckDetailListener(this);
    }

    /**
     * 显示数据
     * @param sn
     */
    public void showDetailData(String sn){
        SearchAsset asset = repairDetailModel.getAssetBySn(sn);
        RepailDetail repailDetail = repairDetailModel.getRepailDetailBySn(sn);
        regisgerDetailView.showDetail(repailDetail);

    }

    /**
     * 保存数据
     * @param repailDetail
     */
    public void saveDetailData(RepailDetail repailDetail){
        RepailDetail repailDetail1 = regisgerDetailView.saveRepailDetail(repailDetail);
//        repairDetailModel.saveRepairDetailata(repailDetail1);
    }
    @Override
    public void onFailure(Call call, IOException e) {
        regisgerDetailView.hideProgressDialog();
        regisgerDetailView.showToast(e.getMessage());
    }

    @Override
    public void onResponse(Call call, Response response) {
        regisgerDetailView.hideProgressDialog();
        if(response.isSuccessful()){
            if(response.code()==200){

            }else{
                regisgerDetailView.showToast(response.message());
            }
        }else{
            regisgerDetailView.showToast(MyApplication.APP_CONTEXT.getString(R.string.get_data_fail));
        }
    }
}
